var electricNumber = "";
var openId = "";
$(function(e){
	receiveData();
	dataInit();
});

function dataInit(){
	codes = $.req("code");
	AjaxPostUtil.request({url : path+"1853f065ae4845f2a235af6449c18767", params:{codes:codes}, type : 'json', callback : function(json){
		if(json.returnCode == '-999'){//重新登记
			openId = json.bean.openId;
			location.href='../../html/wechat_signup/wechat_signup.html?openId='+openId;
		}else if(json.returnCode == '-888'){
			//关闭当前页面，返回到微信主页面
			swal({ title : "提示", text : "信息正在审核中...", type : "warning" ,closeOnConfirm:false, closeOnCancel:false },function(){
				wx.closeWindow();
			});
		}else if(json.returnCode == '-777'){
			swal({ title : "提示", text : "信息审核失败，请重新登记！", type : "warning", closeOnConfirm:false, closeOnCancel:false}, function(){
				openId = json.bean.openId;
				location.href='../../html/wechat_signup/wechat_signup.html?openId='+openId;
			});
		}else if(json.returnCode == 0){//审核成功
			$("#houseNum").val(json.bean.hInfo);
			electricNumber = json.bean.electricNumber;
			getElectircInfo();
			
		}else{
			swal({ title : "警告", text : "请重新打开页面", type : "warning" ,closeOnConfirm:false, closeOnCancel:false },function(){
				wx.closeWindow();
			});
		}
	}});
	
}

function getElectircInfo(){
	AjaxPostUtil.request({url : path+"f2b2dc803547449588de6af39eb1af04", params:{}, type : 'json', callback : function(json){
		console.log(json);
		if(json.returnCode == 0){
			var source = $("#selectElectric").html();
			var template = Handlebars.compile(source);
			$("#electricDiv").html(template(json));
		}else{
			swal({ title : "警告", text : json.returnMessage, type : "warning" }); 
		}
	}});
}